package com.fy.proj5_permission_transaction_cache.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/test")
public class TestController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/db-check")
    public Map<String, Object> checkDatabase() {
        // 查询所有用户，包括已删除和未删除的
        List<Map<String, Object>> allUsers = jdbcTemplate.queryForList("SELECT * FROM users");
        // 特别查询ID为2的用户
        List<Map<String, Object>> userWithId2 = jdbcTemplate.queryForList("SELECT * FROM users WHERE id = 2");
        
        return Map.of(
            "allUsers", allUsers,
            "userWithId2Exists", !userWithId2.isEmpty(),
            "message", "物理删除功能验证完成"
        );
    }
}